package com.basiclib.utils

import android.app.Dialog
import android.content.Context
import com.basiclib.widget.OnDialogDismissListener

const val STATUS_SUCESS = 0
const val STATUS_ERROR = 1
const val STATUS_LOADING = 2

class DialogManager {
    private var dialog: Dialog? = null

    object Holder {
        val instance = DialogManager()
    }

    companion object {
        fun instance(): DialogManager {
            return Holder.instance
        }
    }

    fun showProgressBarDialog(
        ctx: Context,
        msg: String = "",
        status: Int = STATUS_LOADING,
        errorMsg: String = "",
        tag: Int = -1,
        listener: OnDialogDismissListener? = null
    ): Dialog? {
        try {
            dimissDialog()
            return dialog
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return null
    }

    fun dimissDialog() {
        dialog?.dismissExt()
    }
}